<template>
    <Form ref="formValidate" class="exform" :model="formValidate" :label-width="80" :rules="ruleValidate">
		<FormItem label="共同承担项目情况	" prop="commonproject.zh" :label-width="120" style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.commonproject.zh" placeholder="共同承担项目情况	" style="width:80%">
			</Input>
		</FormItem>
		<FormItem label="成员姓名" prop="membername.zh"  :label-width="120" style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.membername.zh" placeholder="成员姓名" style="width:80%">
			</Input>
		</FormItem>
		<FormItem label="成员身份证号	" prop="memberid"  :label-width="120" style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.memberid" placeholder="成员身份证号	" style="width:80%">
			</Input>
		</FormItem>
		<FormItem label="成员联系电话" prop="memberphone" :label-width="120"  style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.memberphone" placeholder="成员联系电话" style="width:80%">
			</Input>
		</FormItem>
		<FormItem label="成员学历	" prop="membereducation.zh"  :label-width="120"  style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.membereducation.zh" placeholder="成员学历	" style="width:80%">
			</Input>
		</FormItem>
		<FormItem label="成员职称" prop="memberpost.zh" :label-width="120"  style="width:50%;margin-bottom: 50px;">
			<Input v-model="formValidate.memberpost.zh" placeholder="成员职称" style="width:80%">
			</Input>
		</FormItem>
		<div style="width:90%;">
			<FormItem style="width:100%;margin-bottom: 50px;">
			<Button type="primary" @click="handleSubmit('formValidate')">保存</Button>
			</FormItem>
		</div>
		<div style="clear:both"></div>
		<Spin size="large" fix v-if="spinShow"></Spin>
    </Form>
</template>

<script>

  export default {

    props: {
        teacher_id: {
            type: [Number,String],
            default: null
        },
        infoId: {
            type: [Boolean,String,Number],
            default: false
        }
    },
    data () {
      	return {
            infoUrl:`api/teacher/v1/tbbsqualification/info/${this.infoId}`,//请求单条数据
            saveUrl:'',//保存接口
            saveType:null,//保存方式
            spinShow:false,//加载动画

			infoOld:null,

			formValidate: {
				teacher_id:this.teacher_id,
				memberid:null,    //成员身份证号
				memberphone:null,    //成员联系电话    
				shenhe:1,       //审核
				commonproject:{
					zh:'',
					mn:'',
					en:'',
				},    //共同承担项目情况
				membername:{
					zh:'',
					mn:'',
					en:'',
				},    //成员姓名
				membereducation:{
					zh:'',
					mn:'',
					en:'',
				},    //成员学历
				memberpost:{
					zh:'',
					mn:'',
					en:'',
				},    //成员职称
			},
			ruleValidate: {
				// 成员身份证号
				memberid: [            
					{ required: true, message: '请填写成员身份证号', trigger: 'blur' },
				],
				// 成员联系电话
				memberphone: [
					{ required: true, message: '请填写成员联系电话', trigger: 'blur' },
					{ type: 'number', message: '请输入数字格式', trigger: 'blur', transform(value) {
						return Number(value);
					}}
				],
				//共同承担项目情况
				'commonproject.zh': [
					{ required: true, message: '请填写共同承担项目情况', trigger: 'blur' }
				],

				//成员姓名
				'membername.zh': [
					{ required: true, message: '请填写成员姓名', trigger: 'blur' }
				],
				//成员学历
				'membereducation.zh': [
					{ required: true, message: '请填写成员学历', trigger: 'blur' }
				],

				//成员职称
				'memberpost.zh': [
					{ required: true, message: '请填写成员职称', trigger: 'blur' }
				],
			},  
      	}
    },
    methods: {
     
        /************************************************************
         * 
         * 单条数据请求
         * 
         ************************************************************/
        infoData(){
            this.spinShow=true//输入框禁用  
            this.$http.get(this.infoUrl).then(val=>{
                this.infoOld = JSON.parse(JSON.stringify(val.data))
                this.formValidate.shenhe = parseInt(this.infoOld.shenhe)//用于默认选的 审核
                
                this.formValidate.memberid = this.infoOld.memberid// 成员身份证号
                this.formValidate.memberphone = this.infoOld.memberphone// 成员联系电话
                this.formValidate.commonproject = this.infoOld.commonproject// 共同承担项目情况
                this.formValidate.membername = this.infoOld.membername// 成员姓名
                this.formValidate.membereducation = this.infoOld.membereducation// 成员学历
                this.formValidate.memberpost = this.infoOld.memberpost// 成员职称

                this.formValidate.school_id=this.infoOld.school_id;//学校
                this.formValidate.teacher_id=this.infoOld.teacher_id;//教师 
                this.spinShow=false//输入框禁用 
       
            })
            .catch(err => {
				if(err.code && err.code==422) {
					this.$Message.error(err.message);
				}
                this.spinShow=false//输入框禁用 
            });
        },
		
        /************************************************************
         * 
         * 提交时
         * 
         ************************************************************/
		handleSubmit (name) {
			this.$refs[name].validate((valid) => {
                if (valid) {       
                    this.spinShow=true//输入框禁用   
                    this.saveType(this.saveUrl,this.formValidate).then(val=>{
                        this.$emit('showParent',false)
                        this.$emit('backList',true)
                        this.$Message.success(val.message);
                        this.spinShow=false
                    }).catch(err => {
                        if (err.code && err.code == 422) {
                            this.$Message.error(err.message);
                        }
                        this.spinShow=false
                    })  
                } else {
                    this.$Message.error('表单验证失败!');
                }
			})
		},
    },
    created() {
        if(this.infoId==false){
            // add
            this.UpImgShow=true
            this.saveUrl='api/teacher/v1/tbbsqualification/add'
            this.saveType=this.$http.post

        }else{
            // edit
            this.infoData();
            this.saveUrl=`api/teacher/v1/tbbsqualification/edit/${this.infoId}`
            this.saveType=this.$http.post
        }
    },
}
</script>
<style lang="less">
@import'./../public.less';
</style>
